<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('短信提醒电话列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                产品名称：<select id="productname"></select>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="add()" shiro:hasPermission="system:smsphone:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
            <!--    <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:smsphone:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>-->
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:smsphone:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:smsphone:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:smsphone:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:smsphone:remove')}]];
        var prefix = ctx + "system/smsphone";
        var p = ctx +"product/product"
        $.post(p+"/data",function (data){
            console.log("开始")
            if(data.data.length>0){
                for (let i = 0; i < data.data.length; i++) {
                    $('#productname').append(`<option value="`+data.data[i].id+`">`+data.data[i].productName+`</option>`);
                }
            }
            getdata();
        })
       /* $(document).ready(function() {
            $('#productname').select2();
        });*/
        // 监听 select 的 change 事件
        $('#productname').on('change', function() {

            getdata()
        });
        function add(){
            $.modal.openTab("添加",prefix + "/add/"+$("#productname").val());
        }
        function getdata() {
            $.table.refresh()
            var options = {
                url: prefix + "/list",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "短信提醒电话",
                queryParams:queryParams,
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '${comment}',
                    visible: false
                },
              /*  {
                    field: 'productName',
                    title: '产品名称'
                },*/
                {
                    field: 'name',
                    title: '联系人'
                },
                {
                    field: 'phone',
                    title: '电话'
                },
            /*    {
                    field: 'bz',
                    title: '备注'
                },*/
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                       /* actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                    */    actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        }
        function queryParams(params) {
            var search = $.table.queryParams(params);
            search.productId = $("#productname").val();
            return search;
        }
    </script>
</body>
</html>